<?php
namespace Pw\MainBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class TalentType extends AbstractType
{
	
	public function buildForm(FormBuilderInterface $builder, array $options) {
		$heroes = $options['em']->getRepository('PwMainBundle:Hero')->findVisible();
		$choices = array(1 => 'Нет');
		foreach ($heroes as $hero) {
			$choices[$hero->getId()] = $hero->getName();
		}
		$builder->add('heroId', 'choice', array('choices' => $choices));
		$rarities = $options['em']->getRepository('PwMainBundle:TalentRarity')->findAll();
		$choices = array();
		foreach ($rarities as $rarity) {
			$choices[$rarity->getId()] = $rarity->getName();
		}
		$builder->add('rarityId', 'choice', array('choices' => $choices));
		
		$builder->add('name', 'text');
		$builder->add('description', 'textarea');
		$builder->add('lvl', 'integer');
		$builder->add('useCost', 'text');
		$builder->add('learnCost', 'text');
		$builder->add('type', 'text');
		$builder->add('coolDown', 'text');
		$builder->add('icon', 'file');
	}
    public function getName() {
        return 'talent';
    }
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Pw\MainBundle\Entity\Talent',
            'intention'       => 'talent_item',
			'validation_groups' => array('add'),
        ));
		$resolver->setRequired(array('em'));
    }
}
